// 评论的回复弹窗
var textarea = document.querySelector(".reply-text");
var replyBtn = document.querySelector(".reply-btn.disable");
textarea.addEventListener("input", function (e) {
  if (textarea.value == "") {
    replyBtn.setAttribute("disabled", true);
    replyBtn.classList.add("disable");
  } else {
    replyBtn.removeAttribute("disabled");
    replyBtn.classList.remove("disable");
  }
  this.style.height = "inherit";
  this.style.height = `${this.scrollHeight}px`;
});

var cancel = document.querySelector(".top-cancel");
var mask = document.querySelector(".mask");
cancel.onclick = function () {
  mask.style.display = "none";
  document.body.style.overflow = "inherit";
};
var reply = document.getElementsByClassName("reply");

for (let i = 0; i < reply.length; i++) {
  reply[i].onclick = function () {
    document.body.style.overflow = "hidden";
    let cid = reply[i].getAttribute("cid");
    mask.style.display = "flex";
    let comment = document.querySelector(".reply-text").value;
    console.log(comment);
    replyBtn.onclick = function () {
      // 进行二级评论(获取博文id)
      $.ajax({
        url: "/weibo/blog/publishSecondComment",
        type: "post",
        data: {
          id: cid,
          comment,
        },
        success: function (result) {
          console.log("回复成功");
          mask.style.display = "none";
          showCustomAlert("回复成功", true);
          // 获取cid
          let newlist2 = $("#content").find(`.item1[cid=${cid}]`);
          console.log(newlist2);
          $("#content").find(`.item1[cid=${cid}]`).after(`<div class="list2">
       <div class="list2-bar"></div>
       <div class="list2-details">
         <a href="" class="list2-name"><span>XXX:</span></a>
         <span class="list2-content">${comment}</span>
       </div>
       <div class="list2-bottom">
         <div class="list2-time">3-18</div>
       </div>
     </div>`);
        },
      });
    };
  };
}
textarea.onkeyup = function () {
  let ddl = document.querySelector(".ddl");
  let str = textarea.value;
  console.log(textarea.value.length);
  ddl.innerHTML = `还可输入${100 - textarea.value.length}字`;
  if (textarea.value.length >= 100) {
    ddl.innerHTML = "还可输入0字";
    textarea.value = textarea.value.substr(0, 100);
  }
};
